package com.controller;

import com.config.Result;
import com.service.NoticeService;
import com.service.impl.NoticeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Note")
public class NoticeController {

    @Autowired
    NoticeServiceImpl noticeService;

    @PostMapping("/updateNote")
    public Result<?> updateNote(@RequestBody String[] note){
        Boolean aBoolean = noticeService.deleteNote();
        if (aBoolean == null){
            return Result.error("-1","更新失败");
        }
        for (int i = 0; i < note.length; i++) {
            Integer integer = noticeService.insertNote(note[i]);
            if (integer != 1){
                return Result.error("-1","更新失败");
            }
        }
        String[] strings = noticeService.selectNote();
        return Result.success(strings);
    }


    @PostMapping("/selectNote")
    public Result<?> selectNote(){
        String[] strings = noticeService.selectNote();
        if (strings == null){
            return Result.error("-1","查看公告失败");
        }
        return Result.success(strings);
    }
}
